define(function(require, exports, module) {
    var router = require("router");
    // var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function data() {
                return {
                    items: [],
                    page: 1,
                    mounted: 0,
                    nodata:0,
                    user_id: this.$route.params.user_id,
                    publish_text: "创建",
                    showPublishBtn:0,
                    shop_id:0,
                    status:0,
                };
            },
            el: "#pageUserTopic",
            created: function created() {
                this.pid = this.$route.params.pid;
                 if(this.$route.params.shop_id){
                    this.shop_id = this.$route.params.shop_id;
                }
                this.fetchData();
                var _this = this;
                 _this.groupData();
            },
            mounted: function mounted() {
                if (this.mounted == 1) {
                    return;
                }
                //分页
                var _this = this;
                app.pager(function() {
                    console.log(_this.page);
                    if (_this.page > 1 && _this.lastpage != 1 && app.params.loadPage != 1) {
                        app.params.loadPage = 1;
                        _this.fetchData();
                    }
                });
                
               
                this.mounted = 1;
            },
            methods: {
                setStatus:function(status){
                    this.status = status;
                    this.fetchData(1);

                },
                fetchData: function fetchData(reload) {
                    if(reload==1){
                        this.page=1;
                        this.lastpage=0;
                        this.items=[];
                    }
                    var _this = this;
                    var params = {
                        page: this.page
                        
                    };
                    if (_this.pid > 0) {
                        params.pid = this.pid;
                    }
                    if (_this.status > 0) {
                        params.status = this.status;
                    }
                    
                     if (_this.user_id > 0) {
                        params.user_id = this.user_id;
                    }
                    if (_this.shop_id > 0) {
                        params.shop_id = this.shop_id;
                    }
                    
                    app.get("/sns/topic/list", params, function(res) {
                        if (res.code != 200) {
                            app.alert(res.msg);
                            return;
                        }
                        // console.log(res);
                        if (res.data.list.length === 0) {
                            _this.lastpage = 1;
                        }

                        var items = _this.items;
                        _this.items = items.concat(res.data.list);
                        _this.page++;
                        app.params.loadPage = 0;
                        if(_this.items.length === 0){
                            _this.nodata=1;
                            console.log( _this.nodata);
                        }
                    });
                   
                },
                groupData: function groupData() {
                    var _this = this;
                    if (this.pid == 0) {
                        return;
                    }
                    app.post("sns/group/find", {
                        id: this.pid
                    }, function(res, textStatus, xhr) {
                        //var data= JSON.parse(res);
                        if (res.code != 200) {
                            app.alert(res.msg);
                        } else {
                             
                            _this.groupData = res.data;
                            var contentConfig=_this.groupData.content;// JSON.parse(_this.groupData.content);
                            
                            _this.publish_text = contentConfig.issueBntText;
                            if(contentConfig.showPublishBtn===0){
                                _this.showPublishBtn=0;
                            }else{
                                 _this.showPublishBtn=1;
                            }
                             app.setTitle( contentConfig.issuePageTitle);
                        }
                    });
                    // console.log(this);
                }
            }
        }).$mount("#app");
    };
    module.exports = controller;
});
